<template>
    <div>
         <!-- 面包屑导航 -->
         <el-breadcrumb separator-class="el-icon-arrow-right">
           <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
           <el-breadcrumb-item>订单管理</el-breadcrumb-item>
           <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片区域 -->
        <el-card>
            <el-row>
                    <!-- 输入框区域 -->
            <el-input placeholder="请输入内容" v-model="queryInfo.query" @blur='blurInput' clearable @clear='blurInput'>
                <el-button slot="append" icon="el-icon-search" @click='getOrders()'></el-button>
            </el-input>
            </el-row>
            <!-- 数据表格区域 -->
             <el-table :data="OrdersList" stripe style="width: 100%" border>
            <el-table-column  label="#" type='index' width="50"></el-table-column>
            <el-table-column prop="order_number" label="订单编号" width="180"></el-table-column>
            <el-table-column prop="order_price" label="订单价格" width="180"></el-table-column>
            <el-table-column prop="pay_status" label="订单状态" width="180">
                <template slot-scope="props">
                    <el-tag type="danger" v-if='props.row.pay_status==="1"'>已付款</el-tag>
                    <el-tag type="danger" v-else>未付款</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="is_send" label="是否发货" width="180"></el-table-column>
            <el-table-column prop="create_time" label="下单时间" width="180">
                <template slot-scope="props">
                    {{props.row.create_time | format}}
                </template>
            </el-table-column>
            <el-table-column  label="操作" width="180">
                 <el-tooltip class="item" effect="dark" content="修改订单地址" placement="top">
                <el-button type="primary" icon="el-icon-edit" size='mini' @click='toEditOrder'></el-button>
                 </el-tooltip>
                <el-tooltip class="item" effect="dark" content="物流信息" placement="top">
                <el-button type="success" icon="el-icon-location" size='mini' @click='getLocation()'></el-button>
                 </el-tooltip>
            </el-table-column>
             </el-table>
                  <!-- 分页详情 -->
          <div class="block">
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
            :current-page="queryInfo.pegenum" :page-sizes="[1, 2, 5, 8]" :pager-count="5"
             :page-size="queryInfo.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
          </div>
        </el-card>
        <!-- 修改地址对话框 -->
        <el-dialog
        title="修改订单地址"
        :visible.sync="editOrderVisible"
        width="30%"
        @close='resetForm("editOrderFormRef")'
        >
        <el-form :model="editOrderForm" :rules="editOrderRules" ref="editOrderFormRef" label-width="100px" class="demo-ruleForm">
          <el-form-item label="地址" prop="address1">
             <el-cascader
               v-model= "editOrderForm.address1"
              :options="cityData"
              :props="cityObj"
              @change="handleChange"
              width='100%'></el-cascader
              >
          </el-form-item>
           <el-form-item label="活动名称" prop="address2">
            <el-input v-model="editOrderForm.address2"></el-input>
           </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="editOrderVisible = false">取 消</el-button>
          <el-button type="primary">确 定</el-button>
        </span>
        </el-dialog>
        <!-- 获取物流信息对话框 -->
        <el-dialog
          title="物流信息"
          :visible.sync="logisticsVisible"
          width="30%"
          >
          <!-- 物流信息--时间线 -->
          <el-timeline reverse>
            <el-timeline-item
              v-for="(item, index) in logisticsList"
              :key="index"
              :timestamp="item.time">
              {{item.context}}
            </el-timeline-item>
          </el-timeline>
          <span slot="footer" class="dialog-footer">
            <el-button type='success' @click="logisticsVisible = false">取 消</el-button>
          </span>
      </el-dialog>
    </div>
</template>

<script>
import cityData from './citydata.js'
export default {
  data () {
    return {
      queryInfo: {
        query: '',
        pagenum: 1,
        pagesize: 8,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: [],
        order_fapiao_content: '',
        consignee_addr: ''
      },
      //   数据列表
      OrdersList: [],
      //   总数
      total: 0,
      // 省市区数据
      cityData: cityData,
      // 地址数据对象
      editOrderForm: {
        address1: [],
        address2: ''
      },
      // 地址选择列表
      cityKey: [],
      // 城市配置对象
      cityObj: {
        label: 'label',
        value: 'value',
        children: 'children',
        expandTrigger: 'hover'
      },
      // 编辑对话框的显示
      editOrderVisible: false,
      // 物流信息对话框的显示
      logisticsVisible: false,
      // 物流信息列表
      logisticsList: [],
      // 地址规则
      editOrderRules: {
        address1: [
          { required: true, message: '请选择活动区域', trigger: 'change' }
        ],
        address2: [
          { required: true, message: '请选择输入详细地址', trigger: 'blur' }
        ]
      }
    }
  },
  created () {
    //   获取订单数据
    this.getOrdersList()
  },
  methods: {
    // 获取订单数据
    async getOrdersList () {
      const data = await this.$http.get('orders', {
        params: this.queryInfo
      })
      if (data.meta.status === 200) {
        this.OrdersList = data.data.goods
        this.total = data.data.total
      } else {
        return this.$message.success('获取数据失败')
      }
    },
    // 输入清空触发事件
    blurInput () {
      this.getOrdersList()
    },
    // 点击搜索触发事件
    getOrders () {
      this.getOrdersList()
    },
    // 改变页面数据条数
    handleSizeChange (val) {
      this.queryInfo.pagesize = val
      this.getOrdersList()
    },
    // 改变当前页
    handleCurrentChange (val) {
      this.queryInfo.pagenum = val
      this.getOrdersList()
    },
    // 获取物流信息
    async getLocation () {
      // 获取物流信息
      this.logisticsVisible = true
      const data = await this.$http.get('/kuaidi/' + 804909574412544580)
      if (data.meta.status !== 200) return this.$message.error('获取物流信息失败')
      this.logisticsList = data.data
    },
    // 修改订单地址获取订单地址信息
    toEditOrder (row) {
      this.editOrderVisible = true
    },
    // 重置表单
    resetForm (val) {
      this.$refs[val].resetFields()
    },
    // 选择发生变化时触发change事件
    handleChange () {}
  }
}
</script>

<style lang="less" scoped>
.el-row {
    width:400px;
}
</style>
